package bandi.osgi.dalservice.service.users.impl;

import java.util.List;

import bandi.osgi.dal.dao.beans.Device;
import bandi.osgi.dal.dao.beans.User;
import bandi.osgi.dal.dao.devices.DeviceDAO;
import bandi.osgi.dal.dao.users.UsersDAO;
import bandi.osgi.dalservice.service.users.UsersService;

public class UsersServiceImpl implements UsersService {
	
	private UsersDAO ud;
	private DeviceDAO dd;
	
	

	public UsersServiceImpl(UsersDAO ud, DeviceDAO dd) {
		super();
		this.ud = ud;
		this.dd = dd;
	}

	@Override
	public void deleteUser(User user) {
		List<Device> list = dd.getDevices(user);
		for(Device d : list){
			dd.deleteDevice(d);
		}
		ud.deleteUser(user);
		
	}

	@Override
	public List<User> getAllUsers() {
		return ud.getAllUsers();
	}

	@Override
	public User getUser(long userID) {
		return ud.getUser(userID);
	}

	@Override
	public User getUser(String userName) {
		return ud.getUser(userName);
	}

	@Override
	public void insertUser(User user) {
		ud.insertUser(user);
	}

	@Override
	public void updateUser(User user) {
		ud.updateUser(user);
	}

}
